{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from QIFIAccount import QIFI_Account, ORDER_DIRECTION"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "myacc =  QIFI_Account(username='myacc1', password='myacc1', model=\"BACKTEST\", init_cash=10000000, nodatabase=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Create new Account\n",
      "pretend to save to database myacc1/\n",
      "{'account_cookie': 'myacc1', 'password': 'myacc1', 'databaseip': '', 'model': 'BACKTEST', 'ping_gap': 5, 'portfolio': 'QAPaperTrade', 'broker_name': 'QAPaperTrading', 'capital_password': '', 'bank_password': '', 'bankid': 'QASIM', 'investor_name': '', 'money': 10000000, 'pub_host': '', 'trade_host': '', 'taskid': '6b31cfb7-30b7-49ed-bb6f-6d025f6dee84', 'sourceid': 'QIFI_Account', 'updatetime': '', 'wsuri': 'ws://www.yutiansut.com:7988', 'bankname': 'QASIMBank', 'trading_day': '', 'status': 200, 'accounts': {'user_id': 'myacc1', 'currency': 'CNY', 'pre_balance': 0, 'deposit': 10000000, 'withdraw': 0, 'WithdrawQuota': 0, 'close_profit': 0, 'commission': 0, 'premium': 0, 'static_balance': 0, 'position_profit': 0, 'float_profit': 0, 'balance': 10000000, 'margin': 0, 'frozen_margin': 0, 'frozen_commission': 0.0, 'frozen_premium': 0.0, 'available': 10000000, 'risk_ratio': 0.0}, 'trades': {}, 'positions': {}, 'orders': {}, 'event': {'2020-12-25 02:13:46_728522': '转账成功 10000000'}, 'transfers': {'0': {'datetime': 433241234123, 'currency': 'CNY', 'amount': 10000000, 'error_id': 0, 'error_msg': '成功'}}, 'banks': {'QASIM': {'id': 'QASIM', 'name': 'QASIMBank', 'bank_account': '', 'fetch_amount': 0.0, 'qry_count': 0}}, 'frozen': {}, 'settlement': {}}\n"
     ]
    }
   ],
   "source": [
    "myacc.initial()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "持仓\n"
     ]
    }
   ],
   "source": [
    "\n",
    "print('持仓')\n",
    "assert(myacc.positions=={})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myacc.positions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2020-12-25 02:13:47_512522'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myacc.dtstr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "''"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myacc.datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'volume_long': 0, 'volume_short': 0, 'volume_long_frozen': 0, 'volume_short_frozen': 0}\n",
      "{'volume_long': 0, 'volume_short': 0}\n",
      "order check success\n",
      "下单成功 22c7619a-79f5-4df0-a71c-77568e573cce\n"
     ]
    }
   ],
   "source": [
    "order = myacc.send_order('000001', 100, 12, ORDER_DIRECTION.BUY, datetime='2020-01-01')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'account_cookie': 'myacc1',\n",
       " 'user_id': 'myacc1',\n",
       " 'instrument_id': '000001',\n",
       " 'towards': 1,\n",
       " 'exchange_id': 'stock_cn',\n",
       " 'order_time': '2020-12-25 02:13:48_904521',\n",
       " 'volume': 100,\n",
       " 'price': 12.0,\n",
       " 'order_id': '22c7619a-79f5-4df0-a71c-77568e573cce',\n",
       " 'seqno': 1,\n",
       " 'direction': 'BUY',\n",
       " 'offset': 'OPEN',\n",
       " 'volume_orign': 100,\n",
       " 'price_type': 'LIMIT',\n",
       " 'limit_price': 12.0,\n",
       " 'time_condition': 'GFD',\n",
       " 'volume_condition': 'ANY',\n",
       " 'insert_date_time': 1.608833628903523e+18,\n",
       " 'exchange_order_id': '6ae9e352-4cca-40d7-a479-7edff8dc2c06',\n",
       " 'status': 'ALIVE',\n",
       " 'volume_left': 100,\n",
       " 'last_msg': '已报'}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "order"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'22c7619a-79f5-4df0-a71c-77568e573cce': {'amount': 100,\n",
       "  'coeff': 12.0,\n",
       "  'money': 1200.0}}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myacc.frozen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9998800.0"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myacc.available"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "全部成交 22c7619a-79f5-4df0-a71c-77568e573cce\n",
      "update trade\n"
     ]
    }
   ],
   "source": [
    "\n",
    "myacc.make_deal(order)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'22c7619a-79f5-4df0-a71c-77568e573cce': {'amount': 0,\n",
       "  'coeff': 12.0,\n",
       "  'money': 0}}"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myacc.frozen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myacc.positions['stock_cn.000001'].volume_long"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "myacc.balance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12.0"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myacc.get_position('stock_cn.000001').last_price"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1200.0"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myacc.get_position('stock_cn.000001').open_cost_long"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "myacc.datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "myacc.on_price_change('000001', 13, '2020-01-01')\n",
    "#myacc.get_position('stock_cn.000001').message"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stock_cn.000001': < QAPOSITION 000001 amount 100/0 >}"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myacc.positions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2020-01-01'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myacc.datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100.0"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myacc.float_profit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10000100.0"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myacc.balance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "pos = myacc.get_position('000001')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'code': '000001',\n",
       " 'instrument_id': '000001',\n",
       " 'user_id': 'quantaxis',\n",
       " 'portfolio_cookie': 'portfolio',\n",
       " 'username': 'quantaxis',\n",
       " 'position_id': 'a16d2ead-3eb4-4e3d-b11f-06209323e48b',\n",
       " 'account_cookie': 'quantaxis',\n",
       " 'frozen': {},\n",
       " 'name': None,\n",
       " 'spms_id': None,\n",
       " 'oms_id': None,\n",
       " 'market_type': 'stock_cn',\n",
       " 'exchange_id': 'stock_cn',\n",
       " 'moneypreset': 100000,\n",
       " 'moneypresetLeft': 98800.0,\n",
       " 'lastupdatetime': '',\n",
       " 'volume_long_today': 100,\n",
       " 'volume_long_his': 0,\n",
       " 'volume_long': 100,\n",
       " 'volume_long_yd': 0,\n",
       " 'volume_short_yd': 0,\n",
       " 'volume_short_today': 0,\n",
       " 'volume_short_his': 0,\n",
       " 'volume_short': 0,\n",
       " 'pos_long_his': 0,\n",
       " 'pos_long_today': 100,\n",
       " 'pos_short_his': 0,\n",
       " 'pos_short_today': 0,\n",
       " 'volume_long_frozen_today': 0,\n",
       " 'volume_long_frozen_his': 0,\n",
       " 'volume_long_frozen': 0,\n",
       " 'volume_short_frozen_today': 0,\n",
       " 'volume_short_frozen_his': 0,\n",
       " 'volume_short_frozen': 0,\n",
       " 'margin_long': 1200.0,\n",
       " 'margin_short': 0,\n",
       " 'margin': 1200.0,\n",
       " 'position_price_long': 12.0,\n",
       " 'position_cost_long': 1200.0,\n",
       " 'position_price_short': 0,\n",
       " 'position_cost_short': 0.0,\n",
       " 'open_price_long': 12.0,\n",
       " 'open_cost_long': 1200.0,\n",
       " 'open_price_short': 0,\n",
       " 'open_cost_short': 0.0,\n",
       " 'trades': [],\n",
       " 'orders': {},\n",
       " 'last_price': 13,\n",
       " 'float_profit_long': 100.0,\n",
       " 'float_profit_short': 0.0,\n",
       " 'float_profit': 100.0,\n",
       " 'position_profit_long': 100.0,\n",
       " 'position_profit_short': 0.0,\n",
       " 'position_profit': 100.0}"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pos.message"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'volume_long': 0, 'volume_short': 0, 'volume_long_frozen': 0, 'volume_short_frozen': 0}\n",
      "{'volume_long': 0, 'volume_short': 0}\n",
      "order check success\n",
      "下单成功 1c5d1715-dc4f-4065-8fad-77813a0985e7\n"
     ]
    }
   ],
   "source": [
    "order = myacc.send_order('RB2101', 1, 3800, ORDER_DIRECTION.BUY, datetime='2020-01-01')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'account_cookie': 'myacc1',\n",
       " 'user_id': 'myacc1',\n",
       " 'instrument_id': 'RB2101',\n",
       " 'towards': 1,\n",
       " 'exchange_id': 'SHFE',\n",
       " 'order_time': '2020-12-25 02:28:02_961201',\n",
       " 'volume': 1,\n",
       " 'price': 3800.0,\n",
       " 'order_id': '1c5d1715-dc4f-4065-8fad-77813a0985e7',\n",
       " 'seqno': 3,\n",
       " 'direction': 'BUY',\n",
       " 'offset': 'OPEN',\n",
       " 'volume_orign': 1,\n",
       " 'price_type': 'LIMIT',\n",
       " 'limit_price': 3800.0,\n",
       " 'time_condition': 'GFD',\n",
       " 'volume_condition': 'ANY',\n",
       " 'insert_date_time': 1.608834482961201e+18,\n",
       " 'exchange_order_id': '13063e2e-a37b-4b0a-954b-70bc8688eafb',\n",
       " 'status': 'ALIVE',\n",
       " 'volume_left': 1,\n",
       " 'last_msg': '已报'}"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "order"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "全部成交 1c5d1715-dc4f-4065-8fad-77813a0985e7\n",
      "update trade\n"
     ]
    }
   ],
   "source": [
    "myacc.make_deal(order)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'account_cookie': 'myacc1',\n",
       " 'user_id': 'myacc1',\n",
       " 'instrument_id': 'RB2101',\n",
       " 'towards': 1,\n",
       " 'exchange_id': 'SHFE',\n",
       " 'order_time': '2020-12-25 02:28:02_961201',\n",
       " 'volume': 1,\n",
       " 'price': 3800.0,\n",
       " 'order_id': '1c5d1715-dc4f-4065-8fad-77813a0985e7',\n",
       " 'seqno': 3,\n",
       " 'direction': 'BUY',\n",
       " 'offset': 'OPEN',\n",
       " 'volume_orign': 1,\n",
       " 'price_type': 'LIMIT',\n",
       " 'limit_price': 3800.0,\n",
       " 'time_condition': 'GFD',\n",
       " 'volume_condition': 'ANY',\n",
       " 'insert_date_time': 1.608834482961201e+18,\n",
       " 'exchange_order_id': '13063e2e-a37b-4b0a-954b-70bc8688eafb',\n",
       " 'status': 'FINISHED',\n",
       " 'volume_left': 0,\n",
       " 'last_msg': '全部成交'}"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "order"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['stock_cn.000001', 'SHFE.RB2101'])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myacc.positions.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import QUANTAXIS as QA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stock_cn.000001': < QAPOSITION 000001 amount 100/0 >,\n",
       " 'SHFE.RB2101': < QAPOSITION RB2101 amount 1/0 >}"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myacc.positions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "myacc.on_price_change('RB2101', 3920, '2020-01-01')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1300.0"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myacc.float_profit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'RB2101'"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myacc.get_position('RB2101').code#.open_cost_long"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'name': '螺纹钢',\n",
       " 'unit_table': 10,\n",
       " 'price_tick': 1.0,\n",
       " 'buy_frozen_coeff': 0.09,\n",
       " 'sell_frozen_coeff': 0.09,\n",
       " 'exchange': 'SHFE',\n",
       " 'commission_coeff_peramount': 0.0001,\n",
       " 'commission_coeff_pervol': 0,\n",
       " 'commission_coeff_today_peramount': 0.0001,\n",
       " 'commission_coeff_today_pervol': 0}"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myacc.get_position('RB2101').market_preset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "myacc.get_position('RB2101').code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_values([{'amount': 0, 'coeff': 12.0, 'money': 0}, {'amount': 0, 'coeff': 3420.0, 'money': 0}])"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myacc.frozen.values()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "settle\n",
      "pretend to save to database myacc1/2020-01-01\n",
      "{'account_cookie': 'myacc1', 'password': 'myacc1', 'databaseip': '', 'model': 'BACKTEST', 'ping_gap': 5, 'portfolio': 'QAPaperTrade', 'broker_name': 'QAPaperTrading', 'capital_password': '', 'bank_password': '', 'bankid': 'QASIM', 'investor_name': '', 'money': 9960800.0, 'pub_host': '', 'trade_host': '', 'taskid': '6b31cfb7-30b7-49ed-bb6f-6d025f6dee84', 'sourceid': 'QIFI_Account', 'updatetime': '', 'wsuri': 'ws://www.yutiansut.com:7988', 'bankname': 'QASIMBank', 'trading_day': '2020-01-01', 'status': 200, 'accounts': {'user_id': 'myacc1', 'currency': 'CNY', 'pre_balance': 0, 'deposit': 10000000, 'withdraw': 0, 'WithdrawQuota': 0, 'close_profit': 0, 'commission': 0, 'premium': 0, 'static_balance': 0, 'position_profit': 1300.0, 'float_profit': 1300.0, 'balance': 10001300.0, 'margin': 39200.0, 'frozen_margin': 0, 'frozen_commission': 0.0, 'frozen_premium': 0.0, 'available': 9960800.0, 'risk_ratio': 0.004049473568436102}, 'trades': {'605110c0-8017-49db-8c7d-6e3ff1ab29a7': {'seqno': 2, 'user_id': 'myacc1', 'trade_id': '605110c0-8017-49db-8c7d-6e3ff1ab29a7', 'exchange_id': 'stock_cn', 'instrument_id': '000001', 'order_id': '22c7619a-79f5-4df0-a71c-77568e573cce', 'exchange_trade_id': '605110c0-8017-49db-8c7d-6e3ff1ab29a7', 'direction': 'BUY', 'offset': 'OPEN', 'volume': 100, 'price': 12.0, 'trade_time': '2020-12-25 02:14:57_970180', 'commission': 0.0, 'trade_date_time': 1.60883369797018e+18}, 'ba2b32bd-0686-4858-919d-1c94097d82f5': {'seqno': 4, 'user_id': 'myacc1', 'trade_id': 'ba2b32bd-0686-4858-919d-1c94097d82f5', 'exchange_id': 'SHFE', 'instrument_id': 'RB2101', 'order_id': '1c5d1715-dc4f-4065-8fad-77813a0985e7', 'exchange_trade_id': 'ba2b32bd-0686-4858-919d-1c94097d82f5', 'direction': 'BUY', 'offset': 'OPEN', 'volume': 1, 'price': 3800.0, 'trade_time': '2020-12-25 02:29:09_837601', 'commission': 0.0, 'trade_date_time': 1.608834549837601e+18}}, 'positions': {'stock_cn.000001': {'code': '000001', 'instrument_id': '000001', 'user_id': 'quantaxis', 'portfolio_cookie': 'portfolio', 'username': 'quantaxis', 'position_id': 'a16d2ead-3eb4-4e3d-b11f-06209323e48b', 'account_cookie': 'quantaxis', 'frozen': {}, 'name': None, 'spms_id': None, 'oms_id': None, 'market_type': 'stock_cn', 'exchange_id': 'stock_cn', 'moneypreset': 100000, 'moneypresetLeft': 98800.0, 'lastupdatetime': '', 'volume_long_today': 100, 'volume_long_his': 0, 'volume_long': 100, 'volume_long_yd': 0, 'volume_short_yd': 0, 'volume_short_today': 0, 'volume_short_his': 0, 'volume_short': 0, 'pos_long_his': 0, 'pos_long_today': 100, 'pos_short_his': 0, 'pos_short_today': 0, 'volume_long_frozen_today': 0, 'volume_long_frozen_his': 0, 'volume_long_frozen': 0, 'volume_short_frozen_today': 0, 'volume_short_frozen_his': 0, 'volume_short_frozen': 0, 'margin_long': 1200.0, 'margin_short': 0, 'margin': 1200.0, 'position_price_long': 12.0, 'position_cost_long': 1200.0, 'position_price_short': 0, 'position_cost_short': 0.0, 'open_price_long': 12.0, 'open_cost_long': 1200.0, 'open_price_short': 0, 'open_cost_short': 0.0, 'trades': [], 'orders': {}, 'last_price': 13, 'float_profit_long': 100.0, 'float_profit_short': 0.0, 'float_profit': 100.0, 'position_profit_long': 100.0, 'position_profit_short': 0.0, 'position_profit': 100.0}, 'SHFE.RB2101': {'code': 'RB2101', 'instrument_id': 'RB2101', 'user_id': 'quantaxis', 'portfolio_cookie': 'portfolio', 'username': 'quantaxis', 'position_id': '139e3d59-ee4d-4d19-9598-a8da248e86a0', 'account_cookie': 'quantaxis', 'frozen': {}, 'name': None, 'spms_id': None, 'oms_id': None, 'market_type': 'future_cn', 'exchange_id': 'SHFE', 'moneypreset': 100000, 'moneypresetLeft': 62000.0, 'lastupdatetime': '', 'volume_long_today': 1, 'volume_long_his': 0, 'volume_long': 1, 'volume_long_yd': 0, 'volume_short_yd': 0, 'volume_short_today': 0, 'volume_short_his': 0, 'volume_short': 0, 'pos_long_his': 0, 'pos_long_today': 1, 'pos_short_his': 0, 'pos_short_today': 0, 'volume_long_frozen_today': 0, 'volume_long_frozen_his': 0, 'volume_long_frozen': 0, 'volume_short_frozen_today': 0, 'volume_short_frozen_his': 0, 'volume_short_frozen': 0, 'margin_long': 38000.0, 'margin_short': 0, 'margin': 38000.0, 'position_price_long': 3800.0, 'position_cost_long': 38000.0, 'position_price_short': 0, 'position_cost_short': 0, 'open_price_long': 3800.0, 'open_cost_long': 38000.0, 'open_price_short': 0, 'open_cost_short': 0, 'trades': [], 'orders': {}, 'last_price': 3920, 'float_profit_long': 1200.0, 'float_profit_short': 0, 'float_profit': 1200.0, 'position_profit_long': 1200.0, 'position_profit_short': 0, 'position_profit': 1200.0}}, 'orders': {'22c7619a-79f5-4df0-a71c-77568e573cce': {'account_cookie': 'myacc1', 'user_id': 'myacc1', 'instrument_id': '000001', 'towards': 1, 'exchange_id': 'stock_cn', 'order_time': '2020-12-25 02:13:48_904521', 'volume': 100, 'price': 12.0, 'order_id': '22c7619a-79f5-4df0-a71c-77568e573cce', 'seqno': 1, 'direction': 'BUY', 'offset': 'OPEN', 'volume_orign': 100, 'price_type': 'LIMIT', 'limit_price': 12.0, 'time_condition': 'GFD', 'volume_condition': 'ANY', 'insert_date_time': 1.608833628903523e+18, 'exchange_order_id': '6ae9e352-4cca-40d7-a479-7edff8dc2c06', 'status': 'FINISHED', 'volume_left': 0, 'last_msg': '全部成交'}, '1c5d1715-dc4f-4065-8fad-77813a0985e7': {'account_cookie': 'myacc1', 'user_id': 'myacc1', 'instrument_id': 'RB2101', 'towards': 1, 'exchange_id': 'SHFE', 'order_time': '2020-12-25 02:28:02_961201', 'volume': 1, 'price': 3800.0, 'order_id': '1c5d1715-dc4f-4065-8fad-77813a0985e7', 'seqno': 3, 'direction': 'BUY', 'offset': 'OPEN', 'volume_orign': 1, 'price_type': 'LIMIT', 'limit_price': 3800.0, 'time_condition': 'GFD', 'volume_condition': 'ANY', 'insert_date_time': 1.608834482961201e+18, 'exchange_order_id': '13063e2e-a37b-4b0a-954b-70bc8688eafb', 'status': 'FINISHED', 'volume_left': 0, 'last_msg': '全部成交'}}, 'event': {'2020-12-25 02:13:46_728522': '转账成功 10000000'}, 'transfers': {'0': {'datetime': 433241234123, 'currency': 'CNY', 'amount': 10000000, 'error_id': 0, 'error_msg': '成功'}}, 'banks': {'QASIM': {'id': 'QASIM', 'name': 'QASIMBank', 'bank_account': '', 'fetch_amount': 0.0, 'qry_count': 0}}, 'frozen': {'22c7619a-79f5-4df0-a71c-77568e573cce': {'amount': 0, 'coeff': 12.0, 'money': 0}, '1c5d1715-dc4f-4065-8fad-77813a0985e7': {'amount': 0, 'coeff': 3420.0, 'money': 0}}, 'settlement': {}}\n"
     ]
    }
   ],
   "source": [
    "myacc.settle()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{}"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myacc.trades"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{}"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myacc.frozen"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
